import React from 'react';
import { Router, Route, Switch, Redirect} from 'dva/router';

import Login from './routes/login/Login';
import NewsSandBox from './routes/sandbox/NewsSandBox';
import App from './routes/App';
import News from './routes/news/News';
import Detail from './routes/news/Detail';

function RouterConfig({ history }) {
  return (
    <Router history={history}>
      <Switch>
        <Route path='/' render={()=>
        <App>
          <Switch>  
              <Route path="/login" component={Login} />
              <Route path="/news" component={News} />
              <Route path="/detail/:id" component={Detail} />
              {/* <Route path="/newsSandBox" component={NewsSandBox} /> */}
              <Route path="/" render={()=>
                localStorage.getItem('token') ? <NewsSandBox/> :<Redirect to='/login' />
              }/>

          </Switch>
        </App>} />
      </Switch>
    </Router>
  );
}

export default RouterConfig;
